import { Component, OnInit, OnChanges, EventEmitter, ViewChild } from '@angular/core';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { DataService } from '../../../services/data.service';
import { FormGroup, FormControl } from '@angular/forms';
import { DetailService } from './detail.service';
import { PublicEventService } from '../public-event.service';
import { FileUploader } from "ng2-file-upload";
import * as _ from 'lodash'
import { environment } from '../../../../environments/environment';
import * as moment from 'moment';
import * as flatpickr from 'flatpickr';
import { zh } from "flatpickr/dist/l10n/zh.js"
import { PublicStepbarComponent } from '../stepbar/stepbar.component';
import { Util } from 'app/common/util';

@Component({
  selector: 'app-detail',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.scss'],
  providers: [DetailService]
})
export class PublicDetailComponent implements OnInit {
  // 子组件-状态条
  @ViewChild(PublicStepbarComponent)
  public stepBar: PublicStepbarComponent;

  //基础信息其他份额信息list
  public otherShareList: any = [
    {
      "sFundName": "asdad",
      "sFundCode": "1245",
      "dIssue": "2018-12-12"
    },
    {
      "sFundName": "asdad",
      "sFundCode": "1245",
      "dIssue": "2018-12-12"
    }
  ];
  // 跳转状态必填项提示信息
  public requiredTips: any = [];
  // 状态树查询
  public treeStatus: any;
  // 用于保存路由中的operate
  public operate = "";
  // 用于保存路由中的index
  public index: any;
  // 用于保存路由中的产品内码
  public nFundNo: any;
  // lodash
  public _: any = _;
  // 获取权限按钮
  public menuResourceSet: any;
  // 是否隐藏保存按钮
  public hideButton = false;
  // 方案设计及立项隐藏审核信息
  public hideShInfo: any = false;
  // 准备报会隐藏“证监会审核”
  public hideZjhshh: any;
  // 审核信息日期必填校验
  public showDateTips: any = [];
  // 审核信息日期必填校验提示
  public showCheckTips: any = [];
  public isAllowWtite: any;
  // 交易所状态
  public booleanExchange: any = true;
  //是否召开持有人大会状态
  public booleansPossessorMt: any;
  // 基础文件数据  GM=公募
  public jcwjGMDataList = [];
  // 审批文件数据
  public spwjGMDataList = [];
  // 产品改造文件数据
  public cpgzGMDataList = [];
  // 其他文件数据
  public qtwjGMDataList = [];
  // 历史附件数据
  public historyGMDataList = [];
  // 用于保存显示的附件列表
  public activeFileList = [];
  // 用于保存激活的文件tab大类
  public activeFileType = "";
  public eventEmit: any;
  public $ = window['$'];
  // 附件历史数据
  public fileHistoryData: any;
  // 产品上传参数
  public sCreatorNo: any;
  public sCreator: any;
  public sAttachCode: any;
  public nAttachNo: any;
  public sAttachType: any;
  public parentCode: any;
  public parentType: any;
  public sFundType: any;
  // 产品文件列表数据拼装
  // 基础文件
  public jcwjGM: any;
  // 审批文件
  public spwjGM: any;
  // 产品改造文件
  public cpgzwjGM: any;
  // 上传文件名
  public fileName;
  // 其他文件
  public qtwjGM: any;
  // 其他文件
  public historyGM: any;
  // 产品基本信息
  public baseInfo: any = {};
  // 产品审核信息
  public checkInfo: any = {};
  //判断审核信息是否为空
  public checkInfoIsNull: any;
  //控制双击显示修改文件夹输入框
  public showChangeFilenameInput = false;
  // 初始化定义uploader变量,用来配置input中的uploader属性
  public uploader: FileUploader = new FileUploader({});
  // 上传文件的名称
  public uploadFileName: any = "";
  // 选择文件状态
  public fileStatus = false;
  // 基金经理
  public managerList = [];
  // 基金经理多选下拉框
  public managerSelectList = [];
  // 备案机构、受托人、托管人
  public distionary: any = {
    RECORDORG_TYPE: [],  // 备案机构
    LINK_PRINCIPAL_NO: [],   //受托人
    TRUSTEE: [],   //  托管人
    INVEST_STYLE: []
  }
  //获取字典值
  public dictionaryList = {
    FUND_CATEGORY_GM: [],
    INVEST_STYLE: [],
    EXCHANGE: []
  };
  // public bankDictionaryList = [];
  //查询单个审核信息得到的产品改造类型
  public remouldType = {
    bgzc: '',
    yqmj: '',
    tzfl: '',
    zsfe: '',
    qtbg: ''
  }
  //基础信息绑定数据
  public baseInfoPost: any = {
    sFundCode: '',
    sFundName: '',
    sFullName: '',
    sFundType: '1',
    sFundCategory: '',
    sIsQdii: '0',
    sInvestStyle: '',
    sPmAccount: '',
    sPmName: '',
    sListType: '0',
    sExchange: '',
    sBank: '',
    dBankConfirm: '',
    sInvestScope: '',
    sBenchmark: '',
    sManagementFee: '',
    sTrusteeFee: '',
    sOtherFee: '',
    dIssue: '',
    dEstablishment: '',
    sCreator: '',
    sCreatorNo: '',
    sIsRegisterChg: '',
    nRegisterChgNo: '',
    sStatus: '',
    sStatusRunning: '',
    sSubStatus: "",
    sSubStatusSet: "",
    sRemark: '',
    dUpdateTime: '',
    dCreateTime: '',
    sOtherCode1: "",
    sOtherCode2: "",
    sOtherCode3: "",
    pmsOtherShareList:[]
  };
  // 审核信息备份，用于校验日期
  public copyCheckInfoPost: any;
  //审核信息绑定数据
  public checkInfoPost = {
    publicissueExamineInfo: {
      sZshRemarkChg: '',
      nAuditNo: '',
      nFundNo: '',
      dLxCommittee: "",
      dAuditCommittee: "",
      dCsrsSb: "",
      dCsrsBz: "",
      dCsrsSl: "",
      dCsrsFeedback: "",
      dCsrsCommitopt: "",
      dCsrsReply: "",
      dCsrsReplyEnd: "",
      dCsrsAnswer: "",
      sPossessorMt: "",
      dPossessorGg: "",
      dPossessorJy: "",
      dRaisePostponeBh: "",
      dRaisePostponePf: "",
      dRaisePostponeHh: "",
      dRatePossessorMt: "",
      dRatePossessorGg: "",
      dRatePossessorJy: "",
      dChgRecordSb: "",
      dChgSb: "",
      dOtherchgRecordSb: "",
      dOtherChgGg: "",
      sRemarkChg: "",
      sFundCode: '',
      sFundName: '',
      sFullName: '',
      sFundType: ''
    },
    bgzc: "",
    yqmj: "",
    tzfl: "",
    zsfe: "",
    qtbg: ""
  };
  //判断延期募集批复时间是否允许修改
  public isDisabledPF = '';
  constructor(
    private route: ActivatedRoute,
    public dataService: DataService,
    private publicDetailService: DetailService,
    public router: Router,
    public publicEventService: PublicEventService
  ) {
    let that = this;
    // 基金经理
    this.getManagerList();
    this.route.params.subscribe((data) => {
      this.operate = data.operate;
      this.nFundNo = data.nFundNo;
      this.index = data.index;
      if (this.operate == 'edit') {
        this.checkInfoPost.publicissueExamineInfo.nFundNo = data.nFundNo;
        // 获取单个产品基础信息
        this.getSingleProductInfo();
        // 获取单个产品审核信息
        this.getSingleCheckInfo();
        // 审核面板按钮控制
        this.ctrlSaveButton();
        // 加载状态树
        this.loadStatusTree();
        window['$']('#attachInfo').removeClass('active');
        window['$']("#tab_2").removeClass('active');
        window['$']("#attachContent").attr('aria-expanded', "false");

        window['$']('#checkInfo').removeClass('active');
        window['$']("#tab_3").removeClass('active');
        window['$']("#checkContent").attr('aria-expanded', "false");

        window['$']("#baseContent").attr('aria-expanded', "true");
        window['$']('#baseInfo').addClass('active');
        window['$']("#tab_1").addClass('active');
      }else if(this.operate == 'add'){
        that.baseInfoPost.pmsOtherShareList.push(
          {
            "sFundCode": "",
            "sFundName": "",
            "dEstablishment": ""
          }
        )
      }
      // 获取权限按钮
      this.menuResourceSet = sessionStorage.getItem('btn-pub');
      // 接收发射过来的数据
      this.publicEventService.hideInfo = new EventEmitter();
      this.publicEventService.hideInfo.subscribe((value: any) => {

        if (this.operate == 'edit') {
          if (value == 1) {
            // 保存按钮控制
            this.publicDetailService.getSingleCheckInfo(this.nFundNo).subscribe(data => {
              if (data) {
                if (data.bgzc == null) {
                  that.hideButton = true;
                } else {
                  that.hideButton = false;
                }
              }
            })
            this.hideShInfo = true;
            this.hideZjhshh = true;
            window['$']('#attachInfo').removeClass('active');
            window['$']("#tab_2").removeClass('active');
            window['$']("#attachContent").attr('aria-expanded', "false");

            window['$']('#checkInfo').removeClass('active');
            window['$']("#tab_3").removeClass('active');
            window['$']("#checkContent").attr('aria-expanded', "false");

            window['$']("#baseContent").attr('aria-expanded', "true");
            window['$']('#baseInfo').addClass('active');
            window['$']("#tab_1").addClass('active');
          }
          else if (value == 2) {
            this.hideShInfo = false;
            this.hideZjhshh = true;
            this.hideButton = false;
          } else {
            this.hideShInfo = false;
            this.hideZjhshh = false;
            setTimeout(() => {
              this.ctrldCsrsReply();
            }, 200)
            this.hideButton = false;
          }

        }
      })
      // 接受检查是否为空的事件讯号
      this.publicEventService.checkNullEmit = new EventEmitter();
      this.publicEventService.checkNullEmit.subscribe((value: any) => {
        if (value == "产品管理联席委员会") {
          if (this.checkInfoPost.publicissueExamineInfo.dLxCommittee == '' || this.checkInfoPost.publicissueExamineInfo.dLxCommittee == null) {
            setTimeout(() => {
              window['swal']("提示", "请填写联席委员会召开时间,系统将自动切换状态", "warning");
            }, 200);
            return;
          } else {
            // 联席委员会状态已标记
            setTimeout(() => {
              window['swal']("提示", "联席委员会状态已标记", "warning");
            }, 200)
          }
        } else if (value == "产品审核会") {
          if (this.checkInfoPost.publicissueExamineInfo.dAuditCommittee == '' || this.checkInfoPost.publicissueExamineInfo.dAuditCommittee == null) {
            setTimeout(() => {
              window['swal']("提示", "请填写产品审核会召开时间,系统将自动切换状态", "warning");
            }, 200)
            return;
          } else {
            // 产品审核会状态已标记
            setTimeout(() => {
              window['swal']("提示", "产品审核会状态已标记", "warning");
            }, 200)
          }
        }
        else if (value == "上报证监会") {
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsSb == '' || this.checkInfoPost.publicissueExamineInfo.dCsrsSb == null) {
            setTimeout(() => {
              window['swal']("提示", "请填写证监会上报时间,系统将自动切换状态", "warning");
            }, 200)
            return;
          } else {
            // 产品审核会状态已标记
            setTimeout(() => {
              window['swal']("提示", "上报证监会状态已标记", "warning");
            }, 200)
          }
        }
        else if (value == "证监会审核") {
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsSl == '' || this.checkInfoPost.publicissueExamineInfo.dCsrsSl == null) {
            setTimeout(() => {
              window['swal']("提示", "请填写证监会受理日期,系统将自动切换状态", "warning");
            }, 200)
            return;
          } else {
            // 产品审核会状态已标记
            setTimeout(() => {
              window['swal']("提示", "证监会审核状态已标记", "warning");
            }, 200)
          }
        }
        else if (value == "证监会批复") {
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsReply == '' || this.checkInfoPost.publicissueExamineInfo.dCsrsReply == null) {
            setTimeout(() => {
              window['swal']("提示", "请填写证监会批复时间,系统将自动切换状态", "warning");
            }, 200)
            return;
          } else {
            // 产品审核会状态已标记
            setTimeout(() => {
              window['swal']("提示", "证监会批复状态已标记", "warning");
            }, 200)
          }

        }
      })
      // 解决附件跨域问题
      this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
    })
  }
  ngOnInit() {
    let that = this;
    // 多选下拉框
    window['$'](".select2").select2();
    // 初始化日期控件
    flatpickr.localize(zh);
    // 字典值
    this.dictionaryList = JSON.parse(localStorage.getItem("dictionaryList"));

    // 托管行
    this.getDictionary();
    // this.bankDictionaryList = JSON.parse(localStorage.getItem("bankDictionaryList"));
  }
  // 加载状态树
  loadStatusTree() {
    let that = this;
    var getBody = {
      "nFundNo": this.nFundNo,
    }
    var lastParCollection = [];
    this.publicDetailService.loadTree(getBody).subscribe(data => {
      if (data) {
        _.forEach(data.subTree, function (item, index) {
          if (item.isCheck == 1) {
            lastParCollection.push(item.nOrderId);
          }
        })
        // 获取当前最后已选中父步骤
        var lastParChecked = _.max(lastParCollection);
        // 如果当前状态是“方案设计及立项”，隐藏审核信息的tab
        if (lastParChecked == 1) {
          that.treeStatus = 1;
          if (this.operate == 'edit') {
            // 控制保存按钮
            this.publicDetailService.getSingleCheckInfo(this.nFundNo).subscribe(data => {
              if (data) {
                if (data.bgzc == null) {
                  that.hideButton = true;
                } else {
                  that.hideButton = false;
                }
              }
            })
          }
          this.hideShInfo = true;
          this.hideZjhshh = true;
          window['$']('#attachInfo').removeClass('active');
          window['$']("#tab_2").removeClass('active');
          window['$']("#attachContent").attr('aria-expanded', "false");

          window['$']('#checkInfo').removeClass('active');
          window['$']("#tab_3").removeClass('active');
          window['$']("#checkContent").attr('aria-expanded', "false");

          window['$']("#baseContent").attr('aria-expanded', "true");
          window['$']('#baseInfo').addClass('active');
          window['$']("#tab_1").addClass('active');
        } else if (lastParChecked == 2) {
          that.treeStatus = 2;
          this.hideShInfo = false;
          this.hideZjhshh = true;
          this.hideButton = false;
        } else {
          that.treeStatus = 3;
          this.hideShInfo = false;
          this.hideZjhshh = false;
          setTimeout(() => {
            this.ctrldCsrsReply();
          }, 200)
          this.hideButton = false;
        }
      }
    })
  }
  // 输入日期后切换步骤
  changeLabelAfterInput($event, index) {
    let that = this;
    this.ctrldCsrsReply();

    // 模板传来两个参数，第一个是$event,第二个是标识符
    switch (index) {
      case 1:
        // 是否为空，发送不同的flag到stepbar用以触发事件。
        if (this.checkInfoPost.publicissueExamineInfo.dLxCommittee == '') {
          this.publicEventService.eventEmit.emit("dLxCommitteeCheckedFlagNull")
        } else {
          this.publicEventService.eventEmit.emit("dLxCommitteeCheckedFlag")
        }
        break;
      case 2:
        if (this.checkInfoPost.publicissueExamineInfo.dAuditCommittee == '') {
          this.publicEventService.eventEmit.emit("dAuditCommitteeCheckedFlagNull")
        } else {
          this.publicEventService.eventEmit.emit("dAuditCommitteeCheckedFlag")
        }
        break;
      case 3:
        setTimeout(() => {
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsSb === '') {
            this.publicEventService.eventEmit.emit("dCsrsSbCheckedFlagNull")
          } else if (this.checkInfoPost.publicissueExamineInfo.dCsrsSb !== '') {

            this.publicEventService.eventEmit.emit("dCsrsSbCheckedFlag")
          }
        })
        break;
      case 4:
        setTimeout(() => {
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsSl == '') {
            this.publicEventService.eventEmit.emit("dCsrsSlCheckedFlagNull")
          } else {
            this.publicEventService.eventEmit.emit("dCsrsSlCheckedFlag")
          }
        })
        break;
      case 5:
        setTimeout(() => {
          //计算批复到期日为批复时间+6个月
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsReply !== '' && this.checkInfoPost.publicissueExamineInfo.dCsrsReply !== null) {
            var date = moment(this.checkInfoPost.publicissueExamineInfo.dCsrsReply).add('months', 6).format('YYYY/MM/DD');
            this.checkInfoPost.publicissueExamineInfo.dCsrsReplyEnd = moment(date).format('YYYY-MM-DD');
          }
          if (this.checkInfoPost.publicissueExamineInfo.dCsrsReply == '') {
            this.publicEventService.eventEmit.emit("dCsrsReplyCheckedFlagNull")
          } else {
            this.publicEventService.eventEmit.emit("dCsrsReplyCheckedFlag")
          }
        })
        break;
    }
  }
  //新增产品基础信息
  baseInfoAdd() {
    let that = this;
    this.baseInfoPost.sPmAccount = this.ctrlManagerId();
    this.baseInfoPost.sPmName = this.ctrlManagerName();
    let publicUrl: any = { "url": "/pages/publicoffering/new/detail/add" };
    if (this.requireAdd()) {
      // 判断成立日期不能比发行日期早
      // if (this.beforeTime()) {
      window["swal"]({
        title: "提示",
        text: "是否确定保存基础信息?",
        type: "warning",
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        showCancelButton: true,
        closeOnConfirm: false,
        closeOnCancel: true,
        showLoaderOnConfirm: true
      }, function (isConfirm) {
        if (isConfirm) {
          that.publicDetailService.baseInfoAdd(that.baseInfoPost).subscribe(data => {
            if (data) {
              window['swal']("提示", "新增基础信息成功", "success");
              that.dataService.public_url.emit(publicUrl);
              that.router.navigate(['/pages/publicofferingList/fashjjlx']);
            }
          })
        }
      });
      // } else {
      //   window['swal']("提示", "发行日期不能比成立日期早", "warning");
      // }
    }
  }
  //新增产品审核信息
  checkInfoAdd() {
    let that = this;
    this.showCheckTips = [];
    this.checkInfoPost.publicissueExamineInfo.sFundCode = this.baseInfoPost.sFundCode;
    this.checkInfoPost.publicissueExamineInfo.sFundName = this.baseInfoPost.sFundName;
    this.checkInfoPost.publicissueExamineInfo.sFullName = this.baseInfoPost.sFullName;
    if (that.isDcsrsReply()) {
      that.publicDetailService.getSingleCheckInfo(that.nFundNo).subscribe(data => {
        if (data) {
          if (data.publicissueExamineInfo == null) {
            window["swal"]({
              title: "提示",
              text: "是否确定保存审核信息?",
              type: "warning",
              confirmButtonText: "确认",
              cancelButtonText: "取消",
              showCancelButton: true,
              closeOnConfirm: false,
              closeOnCancel: true,
              showLoaderOnConfirm: true
            }, function (isConfirm) {
              if (isConfirm) {
                that.publicDetailService.checkInfoAdd(that.checkInfoPost.publicissueExamineInfo).subscribe(data => {
                  if (data) {
                    window['swal']("提示", "新增审核信息成功", "success");
                    that.stepBar.loadStatusTree();
                  }
                })
              }
            })
          } else {
            that.checkInfoPost.publicissueExamineInfo.nAuditNo = data.publicissueExamineInfo.nAuditNo;
            that.editCheckInfo();
          }
        }
      })
    } else {
      window['swal']("提示", "批复到期日不能比批复日期早", "warning");
    }

  }
  //编辑产品基础信息
  editBasicInfo() {
    let that = this;
    this.baseInfoPost.sPmAccount = this.ctrlManagerId();
    this.baseInfoPost.sPmName = this.ctrlManagerName();
    this.baseInfoPost['nFundNo'] = this.nFundNo;
    if (this.requireAdd()) {
      //判断成立日期不能比发行日期早
      // if (this.beforeTime()) {
      window["swal"]({
        title: "提示",
        text: "是否确定保存基础信息?",
        type: "warning",
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        showCancelButton: true,
        closeOnConfirm: false,
        closeOnCancel: true,
        showLoaderOnConfirm: true
      }, function (isConfirm) {
        if (isConfirm) {
          that.publicDetailService.editBasic(that.baseInfoPost).subscribe(data => {
            if (data) {
              window['swal']("提示", "基础信息保存成功", "success");
            }
          })
        }
      })
      // } else {
      //   window['swal']("提示", "发行日期不能比成立日期早", "warning");
      // }
    }
  }
  // 编辑产品审核信息
  editCheckInfo() {
    let that = this;
    this.showDateTips = [];
    this.showCheckTips = [];
    if (this.isDcsrsReply()) {
      if (this.checkInfoIsNull == false && this.checkInfoPost.bgzc == '1' || this.checkInfoPost.bgzc == '2' || this.checkInfoPost.bgzc == '3') {
        if (this.checkInfoPost.publicissueExamineInfo.sPossessorMt == '1') {
          if (this.checkInfoPost.publicissueExamineInfo.dPossessorGg == '' || this.checkInfoPost.publicissueExamineInfo.dPossessorGg == null) {
            this.showDateTips.push("持有人大会公告时间");
          }
          if (this.checkInfoPost.publicissueExamineInfo.dPossessorJy == '' || this.checkInfoPost.publicissueExamineInfo.dPossessorJy == null) {
            this.showDateTips.push("持有人大会决议生效时间");
          }
          if (this.showDateTips.length > 0) {
            this.showCheckTips = this.showDateTips.join('、');
            window['swal']("提示", this.showCheckTips + "不能为空", "warning");
          } else {
            window["swal"]({
              title: "提示",
              text: "是否确定保存审核信息?",
              type: "warning",
              confirmButtonText: "确认",
              cancelButtonText: "取消",
              showCancelButton: true,
              closeOnConfirm: false,
              closeOnCancel: true,
              showLoaderOnConfirm: true
            }, function (isConfirm) {
              if (isConfirm) {
                that.publicDetailService.editCheckInfo(that.checkInfoPost).subscribe(data => {
                  if (data) {
                    window['swal']("提示", "修改审核信息成功", "success");
                    that.stepBar.loadStatusTree();
                  }
                })
              }
            })
          }
        } else if (this.checkInfoPost.publicissueExamineInfo.sPossessorMt == '0') {
          window["swal"]({
            title: "提示",
            text: "是否确定保存审核信息?",
            type: "warning",
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            showCancelButton: true,
            closeOnConfirm: false,
            closeOnCancel: true,
            showLoaderOnConfirm: true
          }, function (isConfirm) {
            if (isConfirm) {
              that.publicDetailService.editCheckInfo(that.checkInfoPost).subscribe(data => {
                if (data) {
                  window['swal']("提示", "修改审核信息成功", "success");
                  that.stepBar.loadStatusTree();
                }
              })
            }
          })
        } else if (this.checkInfoPost.publicissueExamineInfo.sPossessorMt == '' || this.checkInfoPost.publicissueExamineInfo.sPossessorMt == null) {
          window['swal']("提示", "请选择是否召开持有人大会", "warning");
        } else {
          window["swal"]({
            title: "提示",
            text: "是否确定保存审核信息?",
            type: "warning",
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            showCancelButton: true,
            closeOnConfirm: false,
            closeOnCancel: true,
            showLoaderOnConfirm: true
          }, function (isConfirm) {
            if (isConfirm) {
              that.publicDetailService.editCheckInfo(that.checkInfoPost).subscribe(data => {
                if (data) {
                  window['swal']("提示", "修改审核信息成功", "success");
                  that.stepBar.loadStatusTree();
                }
              })
            }
          })
        }
      } else {
        window["swal"]({
          title: "提示",
          text: "是否确定保存审核信息?",
          type: "warning",
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          showCancelButton: true,
          closeOnConfirm: false,
          closeOnCancel: true,
          showLoaderOnConfirm: true
        }, function (isConfirm) {
          if (isConfirm) {
            that.publicDetailService.editCheckInfo(that.checkInfoPost).subscribe(data => {
              if (data) {
                window['swal']("提示", "修改审核信息成功", "success");
                that.stepBar.loadStatusTree();
              }
            })
          }
        })
      }
    } else {
      window['swal']("提示", "批复到期日不能比批复日期早", "warning");
    }

  }
  //查询单个产品基础信息
  getSingleProductInfo() {
    let that = this;
    this.managerSelectList = [];
    this.publicDetailService.getSingleProductInfo(this.nFundNo).subscribe(data => {
      if (data) {
        console.info(JSON.stringify(data))
        //将获取到的数据赋予baseInfoPost对象
        that.baseInfoPost.sFundName = data.sFundName;
        that.baseInfoPost.sFundCode = data.sFundCode;
        that.baseInfoPost.sFundType = data.sFundType;
        that.baseInfoPost.sFullName = data.sFullName;
        that.baseInfoPost.sFundCategory = data.sFundCategory;
        that.baseInfoPost.sIsQdii = data.sIsQdii;
        that.baseInfoPost.sInvestStyle = data.sInvestStyle;
        that.baseInfoPost.sPmAccount = data.sPmAccount;
        that.baseInfoPost.sListType = data.sListType;
        that.baseInfoPost.sExchange = data.sExchange;
        that.baseInfoPost.sBank = data.sBank;
        that.baseInfoPost.dBankConfirm = data.dBankConfirm;
        that.baseInfoPost.sInvestScope = data.sInvestScope;
        that.baseInfoPost.sBenchmark = data.sBenchmark;
        that.baseInfoPost.sManagementFee = data.sManagementFee;
        that.baseInfoPost.sTrusteeFee = data.sTrusteeFee;
        that.baseInfoPost.sOtherFee = data.sOtherFee;
        that.baseInfoPost.dIssue = data.dIssue;
        that.baseInfoPost.dEstablishment = data.dEstablishment;
        that.baseInfoPost.sCreator = data.sCreator;
        that.baseInfoPost.sCreatorNo = data.sCreatorNo;
        that.baseInfoPost.sIsRegisterChg = data.sIsRegisterChg;
        that.baseInfoPost.nRegisterChgNo = data.nRegisterChgNo;
        that.baseInfoPost.sStatus = data.sStatus;
        that.baseInfoPost.sStatusRunning = data.sStatusRunning;
        that.baseInfoPost.sRemark = data.sRemark;
        that.baseInfoPost.dUpdateTime = data.dUpdateTime;
        that.baseInfoPost.dCreateTime = data.dCreateTime;
        
        if(data.pmsOtherShareList.length > 0){
          that.baseInfoPost.pmsOtherShareList = data.pmsOtherShareList;
        }else{
          that.baseInfoPost.pmsOtherShareList.push(
            {
              "sFundCode": "",
              "sFundName": "",
              "dEstablishment": ""
            }
          )
        }
        // 基金经理转换
        // _.forEach(data.sPmNames, item => {
        //   that.managerSelectList.push(item);
        // })
        that.managerSelectList = _.concat([], data.sPmNames);
        // 初始化交易所状态
        that.changeExchangeStatus();
        setTimeout(function () {
          // 多选下拉框
          window['$'](".select2").select2();
          window['$']('#sTrusteeSelected').select2({ width: '240px', tags: true });
          window['$']('#sTrusteeSelected').on("select2:select", function (e) {
            that.baseInfoPost.sBank = window['$']('#sTrusteeSelected').select2("val");
          })

          //基金运作方式
          window['$']('#sInvestStyleSelected').select2({ width: '240px', tags: true });
          window['$']('#sInvestStyleSelected').on("select2:select", function (e) {
            that.baseInfoPost.sInvestStyle = window['$']('#sInvestStyleSelected').select2("val");
          })
        }, 100);
      }
    })
  }
  //查询单个产品审核信息
  getSingleCheckInfo() {
    let that = this;
    this.publicDetailService.getSingleCheckInfo(this.nFundNo).subscribe(data => {
      if (data) {
        if (data.publicissueExamineInfo !== null) {
          //查询到的审核信息
          this.checkInfoIsNull = false;
          this.checkInfoPost.publicissueExamineInfo.nAuditNo = data.publicissueExamineInfo.nAuditNo;
          this.checkInfoPost.publicissueExamineInfo.dLxCommittee = data.publicissueExamineInfo.dLxCommittee;
          this.checkInfoPost.publicissueExamineInfo.dAuditCommittee = data.publicissueExamineInfo.dAuditCommittee;
          this.checkInfoPost.publicissueExamineInfo.dCsrsSb = data.publicissueExamineInfo.dCsrsSb;
          this.checkInfoPost.publicissueExamineInfo.dCsrsBz = data.publicissueExamineInfo.dCsrsBz;
          this.checkInfoPost.publicissueExamineInfo.dCsrsSl = data.publicissueExamineInfo.dCsrsSl;
          this.checkInfoPost.publicissueExamineInfo.dCsrsFeedback = data.publicissueExamineInfo.dCsrsFeedback;
          this.checkInfoPost.publicissueExamineInfo.dCsrsCommitopt = data.publicissueExamineInfo.dCsrsCommitopt;
          this.checkInfoPost.publicissueExamineInfo.dCsrsReply = data.publicissueExamineInfo.dCsrsReply;
          this.checkInfoPost.publicissueExamineInfo.dCsrsReplyEnd = data.publicissueExamineInfo.dCsrsReplyEnd;
          this.checkInfoPost.publicissueExamineInfo.dCsrsAnswer = data.publicissueExamineInfo.dCsrsAnswer;
          this.checkInfoPost.publicissueExamineInfo.sPossessorMt = data.publicissueExamineInfo.sPossessorMt;
          this.checkInfoPost.publicissueExamineInfo.dPossessorGg = data.publicissueExamineInfo.dPossessorGg;
          this.checkInfoPost.publicissueExamineInfo.dPossessorJy = data.publicissueExamineInfo.dPossessorJy;
          this.checkInfoPost.publicissueExamineInfo.dRaisePostponeBh = data.publicissueExamineInfo.dRaisePostponeBh;
          this.checkInfoPost.publicissueExamineInfo.dRaisePostponePf = data.publicissueExamineInfo.dRaisePostponePf;
          this.checkInfoPost.publicissueExamineInfo.dRaisePostponeHh = data.publicissueExamineInfo.dRaisePostponeHh;
          this.checkInfoPost.publicissueExamineInfo.dRatePossessorMt = data.publicissueExamineInfo.dRatePossessorMt;
          this.checkInfoPost.publicissueExamineInfo.dRatePossessorGg = data.publicissueExamineInfo.dRatePossessorGg;
          this.checkInfoPost.publicissueExamineInfo.dRatePossessorJy = data.publicissueExamineInfo.dRatePossessorJy;
          this.checkInfoPost.publicissueExamineInfo.dChgRecordSb = data.publicissueExamineInfo.dChgRecordSb;
          this.checkInfoPost.publicissueExamineInfo.dChgSb = data.publicissueExamineInfo.dChgSb;
          this.checkInfoPost.publicissueExamineInfo.dOtherChgGg = data.publicissueExamineInfo.dOtherChgGg;
          this.checkInfoPost.publicissueExamineInfo.dOtherchgRecordSb = data.publicissueExamineInfo.dOtherchgRecordSb;
          this.checkInfoPost.publicissueExamineInfo.sFullName = data.publicissueExamineInfo.sFullName;
          this.checkInfoPost.publicissueExamineInfo.sFundCode = data.publicissueExamineInfo.sFundCode;
          this.checkInfoPost.publicissueExamineInfo.sFundName = data.publicissueExamineInfo.sFundName;
          this.checkInfoPost.publicissueExamineInfo.sFundType = data.publicissueExamineInfo.sFundType;
          this.checkInfoPost.publicissueExamineInfo.sRemarkChg = data.publicissueExamineInfo.sRemarkChg;
          this.checkInfoPost.publicissueExamineInfo.sZshRemarkChg = data.publicissueExamineInfo.sZshRemarkChg;
          this.checkInfoPost.bgzc = data.bgzc;
          this.checkInfoPost.qtbg = data.qtbg;
          this.checkInfoPost.tzfl = data.tzfl;
          this.checkInfoPost.yqmj = data.yqmj;
          this.checkInfoPost.zsfe = data.zsfe;
          // 控制批复日期禁用
          this.ctrldCsrsReply();
          // 初始化变更注册-是否召开持有人大会字段
          setTimeout(function () {
            that.changesPossessorMtStatus();
          }, 200);
        } else {
          this.checkInfoIsNull = true;
        }
      }
    })
  }
  // 获取附件列表
  loadFileTree() {
    let that = this;
    let getBody = {
      "sFundType": 1,
      "nFundNo": this.nFundNo
    }
    this.publicDetailService.getFileTree(getBody).subscribe((data) => {
      if (data) {
        that.activeFileList = [];
        that.jcwjGMDataList = [];
        that.spwjGMDataList = [];
        that.cpgzGMDataList = [];
        that.qtwjGMDataList = [];
        that.historyGMDataList = [];
        _.forEach(data.subTree, function (item, index) {
          // 保存附件列表展示的tab
          that.activeFileList.push(item.sAttachCode);
          switch (item.sAttachCode) {
            case "jcwjGM":
              that.jcwjGM = item.subTree;
              let _jcwjGMDataList = [];
              _.forEach(that.jcwjGM, function (ite) {          // ite是附件小分类
                _.forEach(ite.fileList, function (it) {         // it是附件
                  it.sFundType = ite.sFundType;                 // 附件类型 2
                  it["sParentType"] = item.sAttachType;         // 附件大分类名称 产品方案
                  it["sParentCode"] = ite.sParentCode;          // 附件大分类编码 cpfaYDD
                  it["parentType"] = ite.sAttachType;           // 附件小分类名称 产品需求表
                  it["attachCode"] = ite.sAttachCode;           // 附件小分类编码 cpxqbYDD
                  it["subNodeL"] = ite.fileList.length;         // 附件小分类长度
                  it["sType"] = "";                             // 附件小分类名称
                  it["editStatus"] = "0";                       // 附件名编辑状态
                  it["fileName"] = "";                          // 附件修改名称
                  it["fileType"] = "";                          // 附件后缀
                  _jcwjGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;     // 附件小分类名称
              });
              that.jcwjGMDataList = _jcwjGMDataList;
              break;
            case "spwjGM":
              that.spwjGM = item.subTree;
              let _spwjGMDataList = [];
              _.forEach(that.spwjGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  _spwjGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.spwjGMDataList = _spwjGMDataList;
              break;
            case "cpgzwjGM":
              that.cpgzwjGM = item.subTree;
              let _cpgzGMDataList = [];
              _.forEach(that.cpgzwjGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  _cpgzGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.cpgzGMDataList = _cpgzGMDataList;
              break;
            case "qtwjGM":
              that.qtwjGM = item.subTree;
              let _qtwjGMDataList = [];
              _.forEach(that.qtwjGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  _qtwjGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.qtwjGMDataList = _qtwjGMDataList;
              break;
            case "historyGM":
              that.historyGM = item.subTree;
              let _historyGMDataList = [];
              _.forEach(that.historyGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  _historyGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.historyGMDataList = _historyGMDataList;
              break;
          }
        })
        setTimeout(() => {
          that.activeFileTab();
        }, 200)
      }
    })
  }
  // 新增附件上传栏
  addSubTreeItem(item, type) {
    let that = this;
    let index: any;
    this.activeFileType = item.sParentCode;
    let newItem: any = {
      sType: item.sType,              // 小分类名称
      subNodeL: item.subNodeL + 1,    // 长度+1
      attachCode: item.attachCode,    // 小分类编码
      parentType: item.parentType,    // 小分类名称
      sParentType: item.sParentType,  // 大分类名称
      sParentCode: item.sParentCode,  // 大分类编码
      sAttachParentType: "",
      nAttachNo: "",
      nFundNo: "",
      sAttachType: item.parentType,   // 小分类名称
      sAttachCode: item.attachCode,   // 小分类编码
      sLinkFundnos: null,
      sAttachName: null,
      sLinkPrincipalNo: null,
      sLinkPrincipal: null,
      sStatus: null,
      dCreateTime: null,
      sCreator: null,
      sCreatorNo: null,
      nVersion: null,
      sAttachParentCode: null,
      sPath: null,
      nLastAttachNo: null,
      sFundType: item.sFundType,
      editStatus: "0",
      fileName: "",
      fileType: ""
    }
    switch (type) {
      case 'jcwjGM':
        index = _.indexOf(this.jcwjGMDataList, item);
        this.jcwjGMDataList[index].sType = "";
        this.jcwjGMDataList.splice(index, 0, newItem);
        break;
      case 'spwjGM':
        index = _.indexOf(this.spwjGMDataList, item);
        this.spwjGMDataList[index].sType = "";
        this.spwjGMDataList.splice(index, 0, newItem);
        break;
      case 'cpgzGM':
        index = _.indexOf(this.cpgzGMDataList, item);
        this.cpgzGMDataList[index].sType = "";
        this.cpgzGMDataList.splice(index, 0, newItem);
        break;
      case 'qtwjGM':
        index = _.indexOf(this.qtwjGMDataList, item);
        this.qtwjGMDataList[index].sType = "";
        this.qtwjGMDataList.splice(index, 0, newItem);
        break;
      case 'historyGM':
        index = _.indexOf(this.historyGMDataList, item);
        this.historyGMDataList[index].sType = "";
        this.historyGMDataList.splice(index, 0, newItem);
        break;
    }
  }
  // 获取上传文件名称
  selectedFileOnChanged(event: any) {
    this.uploadFileName = event.target.value;
    this.fileStatus = true;
    // 兼容ie title不出现问题
    this.fileName = event.target.value;
  }
  // 显示上传文件框
  showUploadModal(item) {
    this.activeFileType = item.sParentCode;
    this.sAttachCode = item.attachCode;
    this.sAttachType = item.parentType;
    this.parentCode = item.sParentCode;
    this.parentType = item.sParentType;
    this.sFundType = item.sFundType;
    this.sCreator = sessionStorage.getItem('token');
    this.sCreatorNo = sessionStorage.getItem('token');
    if (item.nAttachNo == null) {
      this.nAttachNo = "";
    } else {
      this.nAttachNo = item.nAttachNo;
    }
    window['$']('#uploadModel').modal('toggle');
  }
  closeModal() {
    window['$']('#uploadModel').modal('toggle');
  }
  // 上传文件
  uploadFile() {
    let that = this;
    let reg = /[\#&*|/:"<>?]/gi;
    if (reg.test(_.last(this.uploader.queue).file.name)) {
      window["swal"]("提示", "文件名含有特殊字符!", "warning");
    } else {
      let fileItem = _.last(this.uploader.queue);
      fileItem.url = environment.server + '/pms/v1/common/fundFile/file?token=' + sessionStorage.getItem('token');
      fileItem.method = "POST";
      fileItem.alias = "file";
      fileItem.formData = [
        { key: "fileName", value: _.last(this.uploader.queue).file.name },
        { key: "nFundNo", value: this.nFundNo },
        { key: "nAttachNo", value: this.nAttachNo },
        { key: "sAttachCode", value: this.sAttachCode },
        { key: "sAttachType", value: this.sAttachType },
        { key: "parentCode", value: this.parentCode },
        { key: "parentType", value: this.parentType },
        { key: "sFundType", value: this.sFundType },
        { key: "sCreator", value: this.sCreator },
        { key: "sCreatorNo", value: this.sCreatorNo }
      ],
        // 添加 POST 其他参数
        this.uploader.onBuildItemForm = (item, form) => {
          _.forEach(fileItem.formData, item => {
            form.append(item.key, item.value);
          });
        };
      window['swal']({
        title: "提示",
        text: "是否确定上传 " + _.last(this.uploader.queue).file.name + " 附件?",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "确认",
        confirmButtonColor: "#DD6B55",
        cancelButtonText: "取消",
        showLoaderOnConfirm: true,
      }, function (isConfirm) {
        if (isConfirm) {
          // 开始上传
          fileItem.upload();
          // 上传一个文件成功的回调
          fileItem.onSuccess = function (response, status, headers) {
            let resVal = JSON.parse(response);
            if (resVal.msg == "成功") {
              window["swal"]("成功", "文件上传成功!", "success");
              window['$']('#uploadModel').modal('hide');
              that.clearFileQueue();
              that.loadFileTree();
            } else {
              window["swal"](resVal.msg, resVal.detailMsg, "error");
              window['$']('#uploadModel').modal('hide');
              that.clearFileQueue();
            }
          }
        }
      })
    }
  }
  // 清除FileUploader上传队列中的所有文件
  clearFileQueue() {
    this.uploader.clearQueue();
    this.fileStatus = false;
    window['$']('#fileInput').val("");
  }

  // 下载附件
  downLoadFile(item) {
    if (item.nAttachNo) {
      Util.attachDownload([item.nAttachNo]);
    } else {
      window['swal']("提示", "暂无文件下载", "warning");
    }
  }

  // 查看历史文件
  showHistoryVersion(item) {
    let that = this;
    this.activeFileType = item.sParentCode;
    this.publicDetailService.getFileHistory(item.nAttachNo).subscribe(data => {
      if (data) {
        that.fileHistoryData = data;
        window['$']("#detail-his-list-modal").modal('show');
      } else {
        window['swal']("提示", "暂无文件", "warning");
      }
    })
  }
  // 删除文件
  delFile(item) {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定删除 " + item.sAttachName + " 附件？",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    }, function (isConfirm) {
      if (isConfirm) {
        that.publicDetailService.delFile(item.nAttachNo).subscribe(data => {
          if (data) {
            window['swal']("成功", "文件已删除！", "success");
            window['$']("#detail-his-list-modal").modal('hide');
            that.loadFileTree();
          } else {
            window['swal']("失败", data.msg, "error");
          }
        })
      }
    })
  }
  // 编辑附件名称
  editFileName(item, type) {
    let that = this;
    // 该附件全名长度
    let len = item.sAttachName.length;
    // 该附件名最后一个.的位置
    let lastDotIndex = item.sAttachName.lastIndexOf(".");
    let index;
    switch (type) {
      case "jcwjGM":
        // 该附件所在列表位置
        index = _.indexOf(this.jcwjGMDataList, item);
        // 获取附件文件名并赋值
        this.jcwjGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        // 获取附件扩展名并赋值
        this.jcwjGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.jcwjGMDataList[index].editStatus = "1";
        break;
      case "spwjGM":
        index = _.indexOf(this.spwjGMDataList, item);
        this.spwjGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.spwjGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.spwjGMDataList[index].editStatus = "1";
        break;
      case "cpgzGM":
        index = _.indexOf(this.cpgzGMDataList, item);
        this.cpgzGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.cpgzGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.cpgzGMDataList[index].editStatus = "1";
        break;
      case "qtwjGM":
        index = _.indexOf(this.qtwjGMDataList, item);
        this.qtwjGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.qtwjGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.qtwjGMDataList[index].editStatus = "1";
        break;
      case "historyGM":
        index = _.indexOf(this.historyGMDataList, item);
        this.historyGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.historyGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.historyGMDataList[index].editStatus = "1";
        break;
    }
  }
  // 修改附件名
  changeFileName(item) {
    let that = this;
    // 去掉附件名首尾空格
    let filename = _.trim(item.fileName);
    if (filename !== "" && filename !== null) {
      let reg = /[\#&*|/:"<>?]/gi;
      if (reg.test(filename)) {
        window["swal"]("提示", "文件名含有特殊字符!", "warning");
      } else {
        let newFileName = encodeURI(filename) + item.fileType;
        window['swal']({
          title: "提示",
          text: "附件名称是否确定修改为 " + filename + " ?",
          type: "warning",
          showCancelButton: true,
          closeOnConfirm: false,
          confirmButtonText: "确认",
          confirmButtonColor: "#DD6B55",
          cancelButtonText: "取消",
          showLoaderOnConfirm: true,
        }, function (isConfirm) {
          if (isConfirm) {
            that.publicDetailService.changeFileName(item.nAttachNo, newFileName).subscribe(data => {
              if (data) {
                window['swal']("成功", "附件名修改成功!", "success");
                that.loadFileTree();
              }
            })
          }
        })
      }
    } else {
      window['swal']("注意", "附件名不能为空", "warning")
    }
  }
  // 取消编辑附件名
  cancelEditFileName(item, type) {
    let index;
    switch (type) {
      case "jcwjGM":
        index = _.indexOf(this.jcwjGMDataList, item);
        this.jcwjGMDataList[index].editStatus = "0";
        break;
      case "spwjGM":
        index = _.indexOf(this.spwjGMDataList, item);
        this.spwjGMDataList[index].editStatus = "0";
        break;
      case "cpgzGM":
        index = _.indexOf(this.cpgzGMDataList, item);
        this.cpgzGMDataList[index].editStatus = "0";
        break;
      case "qtwjGM":
        index = _.indexOf(this.qtwjGMDataList, item);
        this.qtwjGMDataList[index].editStatus = "0";
        break;
      case "historyGM":
        index = _.indexOf(this.historyGMDataList, item);
        this.historyGMDataList[index].editStatus = "0";
        break;
    }
  }
  // 切换tab清空附件tab
  clearFileType() {
    this.activeFileType = "";
  }
  // 激活附件当前tab
  activeFileTab() {
    let that = this;
    window['$']('#jcwjGMList').removeClass('active');
    window['$']('#tab_4').removeClass('active');
    window['$']("#jcwjGMContent").attr('aria-expanded', "false");
    window['$']('#spwjGMList').removeClass('active');
    window['$']('#tab_5').removeClass('active');
    window['$']("#spwjGMContent").attr('aria-expanded', "false");
    window['$']('#cpgzwjGMList').removeClass('active');
    window['$']('#tab_6').removeClass('active');
    window['$']("#cpgzwjGMContent").attr('aria-expanded', "false");
    window['$']('#qtwjGMList').removeClass('active');
    window['$']('#tab_7').removeClass('active');
    window['$']("#qtwjGMContent").attr('aria-expanded', "false");
    window['$']('#historyGMList').removeClass('active');
    window['$']('#tab_8').removeClass('active');
    window['$']("#historyGMContent").attr('aria-expanded', "false");
    if (this.activeFileType == "") {
      this.activeFileType = this.activeFileList[0];
    }
    switch (this.activeFileType) {
      case "jcwjGM":
        window['$']('#jcwjGMList').addClass('active');
        window['$']('#tab_4').addClass('active');
        window['$']("#jcwjGMContent").attr('aria-expanded', "true");
        break;
      case "spwjGM":
        window['$']('#spwjGMList').addClass('active');
        window['$']('#tab_5').addClass('active');
        window['$']("#spwjGMContent").attr('aria-expanded', "true");
        break;
      case "cpgzwjGM":
        window['$']('#cpgzwjGMList').addClass('active');
        window['$']('#tab_6').addClass('active');
        window['$']("#cpgzwjGMContent").attr('aria-expanded', "true");
        break;
      case "qtwjGM":
        window['$']('#qtwjGMList').addClass('active');
        window['$']('#tab_7').addClass('active');
        window['$']("#qtwjGMContent").attr('aria-expanded', "true");
        break;
      case "historyGM":
        window['$']('#historyGMList').addClass('active');
        window['$']('#tab_8').addClass('active');
        window['$']("#historyGMContent").attr('aria-expanded', "true");
        break;
    }
  }
  // 交易所状态
  changeExchangeStatus() {
    if (this.baseInfoPost.sListType == "1") {
      this.booleanExchange = false;
    }
    if (this.baseInfoPost.sListType == "0") {
      this.booleanExchange = true;
      this.baseInfoPost.sExchange = ""
    }
  }
  // 是否召开持有人大会状态
  changesPossessorMtStatus() {
    if (this.checkInfoPost.publicissueExamineInfo.sPossessorMt == "1") {
      window['$']('#dPossessorGg').removeAttr("disabled");
      window['$']('#dPossessorGg').attr("required", "true");
      window['$']('#dPossessorGg').css("background", "white");
      window['$']('#dPossessorJy').removeAttr("disabled");
      window['$']('#dPossessorJy').attr("required", "true");
      window['$']('#dPossessorJy').css("background", "white");
    }
    if (this.checkInfoPost.publicissueExamineInfo.sPossessorMt == "0") {
      window['$']('#dPossessorGg').attr("disabled", "disabled");
      window['$']('#dPossessorGg').attr("required", "false");
      window['$']('#dPossessorGg').css("background", "#eee");
      this.checkInfoPost.publicissueExamineInfo.dPossessorGg = "";
      window['$']('#dPossessorJy').attr("disabled", "disabled");
      window['$']('#dPossessorJy').attr("required", "false");
      window['$']('#dPossessorJy').css("background", "#eee");
      this.checkInfoPost.publicissueExamineInfo.dPossessorJy = "";
    }
  }
  // 判断发行日期是否比成立日期早
  beforeTime() {
    if (this.baseInfoPost.dIssue !== "" && this.baseInfoPost.dIssue !== null && this.baseInfoPost.dEstablishment !== "" && this.baseInfoPost.dEstablishment !== null) {
      if (this.baseInfoPost.dIssue == this.baseInfoPost.dEstablishment) {
        return true;
      } else {
        if (moment(this.baseInfoPost.dEstablishment).isBefore(this.baseInfoPost.dIssue)) {
          return true;
        } else {
          return false;
        }
      }
    } else {
      return true;
    }
  }
  // (批复日期-批复到期日)-日期校验
  isDcsrsReply() {
    if (this.checkInfoPost.publicissueExamineInfo.dCsrsReply !== "" && this.checkInfoPost.publicissueExamineInfo.dCsrsReply !== null && this.checkInfoPost.publicissueExamineInfo.dCsrsReplyEnd !== "" && this.checkInfoPost.publicissueExamineInfo.dCsrsReplyEnd !== null) {
      if (this.checkInfoPost.publicissueExamineInfo.dCsrsReply == this.checkInfoPost.publicissueExamineInfo.dCsrsReplyEnd) {
        return true;
      } else {
        if (moment(this.checkInfoPost.publicissueExamineInfo.dCsrsReply).isBefore(this.checkInfoPost.publicissueExamineInfo.dCsrsReplyEnd)) {
          return true;
        } else {
          return false;
        }
      }
    } else {
      return true;
    }
  }
  // 证监会上报日期、提交意见复函日期未填写时，禁用批复日期的输入框
  ctrldCsrsReply() {
    if (this.checkInfoPost.publicissueExamineInfo.dCsrsSb !== '' && this.checkInfoPost.publicissueExamineInfo.dCsrsSl !== '' && this.checkInfoPost.publicissueExamineInfo.dCsrsSl !== null) {
      window['$']('#dCsrsReply').removeAttr("disabled");
      window['$']('#dCsrsReply').css("background", "white");
    } else {
      this.checkInfoPost.publicissueExamineInfo.dCsrsReply = "";
      window['$']('#dCsrsReply').attr("disabled", "disabled");
      window['$']('#dCsrsReply').css("background", "#eee");
    }
  }
  //计算延期回函到期日为延期募集批复时间+6个月
  calculateDraisePostponeHh($event) {
    setTimeout(() => {
      if (this.checkInfoPost.publicissueExamineInfo.dRaisePostponePf !== '' && this.checkInfoPost.publicissueExamineInfo.dRaisePostponePf !== null) {
        var date = moment(this.checkInfoPost.publicissueExamineInfo.dRaisePostponePf).add('months', 6).format('YYYY/MM/DD');
        this.checkInfoPost.publicissueExamineInfo.dRaisePostponeHh = moment(date).format('YYYY-MM-DD');
      }
    }, 200);
  }
  // 判断是否为改造产品，控制保存按钮
  ctrlSaveButton() {
    let that = this;
    if (this.operate == 'edit') {
      if (this.index == 'fashjjlx') {
        this.publicDetailService.getSingleCheckInfo(this.nFundNo).subscribe(data => {
          if (data) {
            if (data.bgzc == null && data.bgzc == '') {
              that.hideButton = true;
            } else {
              that.hideButton = false;
            }
          }
        })
      }
      else {
        that.hideButton = false;
      }
    }
  }
  //跳转状态时判断必填项
  requireInput(value) {
    let that = this;
    // 存放必填但未填写的字段，用于提示。
    this.requiredTips = [];
    this.publicDetailService.getSingleCheckInfo(this.nFundNo).subscribe((data) => {
      if (data) {
        this.copyCheckInfoPost = data
        if (this.copyCheckInfoPost.publicissueExamineInfo == null) {
          this.requiredTips.push('联席委员会召开时间')
        } else {
          switch (value) {
            // 跳转到已报会在审
            case "3":
              // 联席委员会召开时间
              if (this.copyCheckInfoPost.publicissueExamineInfo.dLxCommittee == "" || this.copyCheckInfoPost.publicissueExamineInfo.dLxCommittee == null) {
                that.requiredTips.push('联席委员会召开时间')
              }
              break;
            // 跳转到已获批
            case "4":
              // 联席委员会召开时间
              if (this.copyCheckInfoPost.publicissueExamineInfo.dLxCommittee == "" || this.copyCheckInfoPost.publicissueExamineInfo.dLxCommittee == null) {
                that.requiredTips.push('联席委员会召开时间')
              }
              // 证监会上报日期
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSb == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSb == null) {
                this.requiredTips.push("证监会上报日期");
              }
              // 受理日期
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSl == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSl == null) {
                this.requiredTips.push("受理日期");
              }
              // 批复日期
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsReply == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsReply == null) {
                this.requiredTips.push("批复日期");
              }
              break;
            // 跳转到已发行
            case "5":
              // 因为跳转到已发行要判断基础信息的发行日期在数据库是否存在，所以要查询基础信息
              this.publicDetailService.getSingleProductInfo(this.nFundNo).subscribe((data) => {
                if (data.dIssue == '' || data.dIssue == null) {
                  that.requiredTips.push('发行日期')
                }
              })
              // 联席委员会召开时间
              if (this.copyCheckInfoPost.publicissueExamineInfo.dLxCommittee == "" || this.copyCheckInfoPost.publicissueExamineInfo.dLxCommittee == null) {
                that.requiredTips.push('联席委员会召开时间')
              }
              // 证监会上报日期
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSb == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSb == null) {
                this.requiredTips.push("证监会上报日期");
              }
              // 受理日期
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSl == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsSl == null) {
                this.requiredTips.push("受理日期");
              }
              // 批复日期
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsReply == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsReply == null) {
                this.requiredTips.push("批复日期");
              }
              // 批复到期日
              if (this.copyCheckInfoPost.publicissueExamineInfo.dCsrsReplyEnd == "" || this.copyCheckInfoPost.publicissueExamineInfo.dCsrsReplyEnd == null) {
                this.requiredTips.push("批复到期日");
              }
              break;
          }
        }
      }
    })
  }
  // 新增必填校验
  requireAdd() {
    let that = this;
    let requiredAddTips = [];
    let sFundName = _.trim(this.baseInfoPost.sFundName);
    let sPmAccount = _.trim(this.baseInfoPost.sPmAccount);
    let sInvestStyle = _.trim(this.baseInfoPost.sInvestStyle);
    if (sFundName == "" || sFundName == null) {
      requiredAddTips.push("产品简称");
    }
    if (this.baseInfoPost.sFundCategory == "" || this.baseInfoPost.sFundCategory == null) {
      requiredAddTips.push("基金类别");
    }
    if (this.baseInfoPost.sIsQdii == "" || this.baseInfoPost.sIsQdii == null) {
      requiredAddTips.push("QDII");
    }
    if (sInvestStyle == "" || sInvestStyle == null) {
      requiredAddTips.push("基金运作方式");
    }
    if (sPmAccount == "" || sPmAccount == null) {
      requiredAddTips.push("基金经理");
    }
    if (this.baseInfoPost.sListType == "" || this.baseInfoPost.sListType == null) {
      requiredAddTips.push("是否上市基金");
    }
    if (this.baseInfoPost.sListType == "1") {
      if (this.baseInfoPost.sExchange == "" || this.baseInfoPost.sExchange == null) {
        requiredAddTips.push("交易所");
      }
    }
    if (requiredAddTips.length > 0) {
      let sRequiredAddTips = requiredAddTips.join("、");
      window['swal']("提示", sRequiredAddTips + "不能为空", "warning");
      return false;
    } else {
      return true;
    }
  }
  // 基金经理
  getManagerList() {
    let that = this;
    this.publicDetailService.getManagerList().subscribe(data => {
      that.managerList = data;
    })
  }
  // 多选下拉框基金经理Id
  ctrlManagerId() {
    let managerIdList: any;
    let managerChecked = [];
    let selected = window['$']('.fields-select').val();
    _.forEach(selected, item => {
      let index1 = item.indexOf("'");
      let index2 = item.lastIndexOf("'");
      let manager = item.substring(index1 + 1, index2);
      managerChecked.push(manager);
    })
    managerIdList = managerChecked.join(",");
    return managerIdList;
  }
  // 多选下拉框基金经理Name
  ctrlManagerName() {
    let that = this;
    let managerNameList: any;
    let managerChecked = [];
    let managerId = this.ctrlManagerId().split(",");
    _.forEach(managerId, item => {
      _.forEach(that.managerList, it => {
        if (item == it.sUserName) {
          managerChecked.push(it.sRealName);
        }
      })
    })
    managerNameList = managerChecked.join(",");
    return managerNameList;
  }
  ngAfterViewInit() {
    let that = this;
    if (this.operate != 'edit') {
      // 托管人
      window['$']('#sTrusteeSelected').select2({ width: '240px', tags: true });
      window['$']('#sTrusteeSelected').on("select2:select", function (e) {
        that.baseInfoPost.sBank = window['$']('#sTrusteeSelected').select2("val");
      })
      //基金运作方式
      window['$']('#sInvestStyleSelected').select2({ width: '240px', tags: true });
      window['$']('#sInvestStyleSelected').on("select2:select", function (e) {
        that.baseInfoPost.sInvestStyle = window['$']('#sInvestStyleSelected').select2("val");
      })
    }
  }
  // 获取备案机构、受托人、托管人下拉框值
  getDictionary() {
    let that = this;
    this.publicDetailService.getDictionary().subscribe(data => {
      if (data) {
        that.distionary.RECORDORG_TYPE = data.RECORDORG_TYPE;
        that.distionary.LINK_PRINCIPAL_NO = data.LINK_PRINCIPAL_NO;
        that.distionary.TRUSTEE = data.TRUSTEE;
        that.distionary.INVEST_STYLE = data.INVEST_STYLE;
        console.log(that.distionary.INVEST_STYLE)
      }
    })
  }
  //其他份额信息点击新增一行
  addOtherShare(index) {
    let body:any = {
      "sFundCode": "",
      "sFundName": "",
      "dEstablishment": ""
    }
    this.baseInfoPost.pmsOtherShareList.splice(index + 1, 0, body);
    // console.log(this.otherShareList)
  }
  //其他份额信息点击删除一行
  delOtherShare(index) {
    let that = this;
    window['swal'](
      {
        type: "warning",
        showCancelButton: true,
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        closeOnConfirm: true,
        showLoaderOnConfirm: true,
        title: "提示",
        text: "<div style='max-height: 200px;overflow-y: auto;'>" + "请确认是否删除选中数据" + "</div>",
        html: true
      }, function () {
        that.baseInfoPost.pmsOtherShareList = _.filter(that.baseInfoPost.pmsOtherShareList, (item: any, index1) => {
          return index != index1;
        })
      }
    );
  }
}
